package com.gather.orm;

/**
 * 测试Person类
 */
public class Person implements Comparable<Person> {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "name " + name + " : "+age ;
    }

    @Override
    public int compareTo(Person o) {
        // 返回 0 表示两者相等（一样的）
        // 先比较姓名
        int i = this.getName().compareTo(o.getName());
        // 再比较年龄 是int 类型 直接相减
        int n = this.getAge() -o.getAge();
        return (i == 0)? n : i;
    }
}
